const App = getApp()
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const FORM = 'FORM';
const DELETE = 'DELETE';
const baseURL = 'http://8.136.205.167/api/';
function request(method, url, data,header= {
  'content-type': 'application/json',
  'token': wx.getStorageSync('token')
}) {
    return new Promise(function(resolve, reject) {
        wx.request({
            url: baseURL + url,
            method: method,
            data: method === POST ? JSON.stringify(data) : data,
            header: header,
            success(res) {
                if (res.data.code == 200) {
                    resolve(res);
                } else {
                    reject('运行时错误,请稍后再试');
                }
            },
            fail(err) {
                //请求失败
                reject(err)
            }
        })
    })
}
const API = {
    
    saveDemand:(data)=> request('post','demand/saveDemand',data,{
        'content-type': 'application/json',
        'token': wx.getStorageSync('token'),
        'userId': wx.getStorageSync('token')
      }),//发布需求
    getPageHotelBuildingList:(data)=> request('get','hotelBuilding/getPageHotelBuildingList',data),//酒店会厅列表
    getPageHotelList:(data)=> request('get','hotel/getPageHotelList',data),//酒店列表
    saveCollect: (data)=> request('post','teacher/getPageTeacherList',data),//添加收藏
    getPageTeacherList: (data)=> request('get','teacher/getPageTeacherList',data),//教师
  workList: (data)=> request('get','teacherWork/getPageTeacherWorkList',data),//作品列表
  teacherList: ()=> request('get','teacher/getPageTeacherList'),//老师列表
  login: (data) => request('post','app/login',data),//登录
  getOpenid: (data) => request('POST', 'wx/sessionKey',data),
  getUserInfo: (data) => request('POST', 'wx/sessionKey',data),
  getBanner: (data) => request('POST', 'banner/list',data),//获取banner
  getPhone: (data) => request('POST', 'wx/phone',data),//获取手机号
  menuList: (data) => request('POST', 'menu/list',data)//获取职业
};
module.exports = {
  API: API
}